
<html><head>
<title>flibs/m_platform - flibs</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.toc,UL.toc UL, UL.toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.section, LI.subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.requirements LI, UL.syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<! -- Generated from file 'platform/m_platform.man' by tcllib/doctools with format 'html'
   -->
<! -- Copyright &copy; 2008 Arjen Markus &lt;arjenmarkus@sourceforge.net&gt;   -- Copyright &copy; 2008 Michael Baudin &lt;michael.baudin@gmail.com&gt;
   -->
<! -- CVS: $Id: m_platform.html,v 1.4 2013/05/13 08:03:19 knystrom Exp $ flibs/m_platform.n
   -->
<body><div class="doctools">
<h1 class="title">flibs/m_platform(n) 1.0  &quot;flibs&quot;</h1>
<div id="name" class="section"><h2><a name="name">Name</a></h2>
<p>flibs/m_platform - Platform-dependent routines and features</p>
</div>
<div id="toc" class="section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="toc">
<li class="section"><a href="#toc">Table Of Contents</a></li>
<li class="section"><a href="#synopsis">Synopsis</a></li>
<li class="section"><a href="#section1">Description</a></li>
<li class="section"><a href="#section2">OVERVIEW</a>
<ul>
<li class="subsection"><a href="#subsection1">Pre-processing macros</a></li>
<li class="subsection"><a href="#subsection2">Compile</a></li>
<li class="subsection"><a href="#subsection3">Operating System dependency</a></li>
<li class="subsection"><a href="#subsection4">System fortran extension</a></li>
<li class="subsection"><a href="#subsection5">Environment variables extension</a></li>
<li class="subsection"><a href="#subsection6">Change directory fortran extension</a></li>
<li class="subsection"><a href="#subsection7">File stat fortran extension</a></li>
<li class="subsection"><a href="#subsection8">Example of compiler settings</a></li>
</ul>
</li>
<li class="section"><a href="#section3">ROUTINES</a></li>
<li class="section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="synopsis">
<ul class="syntax">
<li><a href="#1"><b class="cmd">use m_platform</b></a></li>
<li><a href="#2"><b class="cmd">platform_system</b> (<i class="arg">command</i> <span class="opt">?, status?</span>)</a></li>
<li><a href="#3"><b class="cmd">platform_get_os()</b> result ( currentos )</a></li>
<li><a href="#4"><b class="cmd">platform_osstring</b> (<i class="arg">currentos</i>)</a></li>
<li><a href="#5"><b class="cmd">platform_get_platform()</b> result ( currentplatform )</a></li>
<li><a href="#6"><b class="cmd">platform_platformstring</b> (<i class="arg">currentplatform</i>)</a></li>
<li><a href="#7"><b class="cmd">platform_get_environment_variable</b> ( <i class="arg">envvar</i> <i class="arg">, value</i>)</a></li>
<li><a href="#8"><b class="cmd">platform_cd</b> ( <i class="arg">dirname</i> <span class="opt">?, status?</span>)</a></li>
<li><a href="#9"><b class="cmd">platform_stat</b> ( <i class="arg">filename</i> <i class="arg">, statarray</i> <span class="opt">?, status?</span>)</a></li>
</ul>
</div>
</div>
<div id="section1" class="section"><h2><a name="section1">Description</a></h2>
<p>The <em>m_platform</em> module contains parameters to identify the
platform the program is running on and provides 
several routines to interact with the operating system.</p>
</div>
<div id="section2" class="section"><h2><a name="section2">OVERVIEW</a></h2>
<p>The goal is to make the client source code as independent as possible
from the particular environment, that is</p>
<ul class="itemized">
<li><p>independent from the operating system, so that the 
binaries can be used under Windows, Linux or any other
specific OS without modifying the source code,</p></li>
<li><p>independent from the fortran compiler, so that the 
binaries can be generated with gfortran Intel Fortran, Absoft,
or any other specific compiler without modifying the source code.</p></li>
</ul>
<p>For instance, the <em>m_platform</em> module provides the 
following features :</p>
<ul class="itemized">
<li><p>The parameter PLATFORM_OS identifies the operating system and the
parameter PLATFORM_PLATFORM identifies the general category.</p></li>
<li><p>The subroutine platform_system() hides the platform-specific details of
running an external command or program.</p></li>
</ul>
<p>The function platform_get_os() returns an integer which identifies
the operating system and the function platform_get_platform() identifies
the general category.
For example, the file separator is different on windows (&quot;\&quot;),
unix (&quot;/&quot;) and Mac (&quot;:&quot;). In the following example, extracted from the
m_vfile module included with flibs, the platform_get_platform()
function is used to configure the separator for the current platform.</p>
<pre class="example">
     use m_platform, only : &amp;
       platform_get_platform , &amp;
       PLATFORM_PLATFORM_WINDOWS ,&amp;
       PLATFORM_PLATFORM_UNIX , &amp;
       PLATFORM_PLATFORM_MAC
     integer :: platform
     character (len=1) :: VFILE_PLATFORM_SEPARATOR
     platform = platform_get_platform ()
     select case ( platform )
     case ( PLATFORM_PLATFORM_WINDOWS )
       VFILE_PLATFORM_SEPARATOR = VFILE_PLATFORM_SEPARATOR_WINDOWS
     case ( PLATFORM_PLATFORM_UNIX )
       VFILE_PLATFORM_SEPARATOR = VFILE_PLATFORM_SEPARATOR_UNIX
     case ( PLATFORM_PLATFORM_MAC )
       VFILE_PLATFORM_SEPARATOR = VFILE_PLATFORM_SEPARATOR_MAC
     case default
       print *, &quot;I come from Vega.&quot;
       return
     end select
</pre>
<p>The subroutine platform_system() allows to execute an external program at the 
   system level. This routine is generally provided by the fortran compiler as an
   extension to standard fortran. But some compilers provide the feature
   as a subroutine (for example gfortran), while other compilers provide the 
   feature as a function (for example Intel Fortran). In the following example,
   one execute a Monte-Carlo simulation with no dependency on the specific 
   compiler.</p>
<pre class="example">
      use m_platform, only platform_system
      call platform_system ( &quot;montecarlo.exe&quot; , status )
</pre>
<p>This is a sketch of available routines :</p>
<ul class="itemized">
<li><p>platform_system                       Executes an external command on the system</p></li>
<li><p>platform_get_os                       Returns the current operating system</p></li>
<li><p>platform_get_platform                 Returns the current platform</p></li>
<li><p>platform_get_environment_variable     Get to one environment variable</p></li>
<li><p>platform_cd                           Change the system current directory</p></li>
<li><p>platform_stat                         Get status of a file</p></li>
</ul>
<div id="subsection1" class="subsection"><h3><a name="subsection1">Pre-processing macros</a></h3>
<p>The source code of m_platform is based on pre-processing macro,
which must be configured for the specific couple (OS,compiler) at use.
With most compilers, defining a pre-processing macro simply
consists in enabling the pre-processing with a specific
option and adding &quot;-D&lt;macro&gt;&quot; options on the command-line.</p>
<p>The only mandatory pre-processing macro which must be defined is
the _PLATFORM_OS_&lt;your OS&gt; macro.
Optionnaly, other pre-processing macros may be defined so that
the client code may access to additionnal features.
If a feature is used and the associated macros have not
been defined, the &quot;status&quot; integer of the associated routine
will have the value PLATFORM_ERROR_UNDEFINED_SERVICE.</p>
</div>
<div id="subsection2" class="subsection"><h3><a name="subsection2">Compile</a></h3>
<p>The &quot;make&quot; directory provided with flibs should help the 
use to compile m_platform. The &quot;make/makefile&quot; contains all the 
makefiles necessary for the project, include specific settings
for several compilers. the &quot;make/visualstudio&quot; directory include 
all projects .nfproj and solutions .sln files necessary to 
compile the project with Intel Fortran 8 and Visual Studio 2003.</p>
</div>
<div id="subsection3" class="subsection"><h3><a name="subsection3">Operating System dependency</a></h3>
<p>The m_platform module <em>must</em> be informed of the specific OS for which
it is compiled. One of the following pre-processing macros <em>must</em> be
defined to set the spefic OS at use :</p>
<ul class="itemized">
<li><p>_PLATFORM_OS_WINDOWS_95</p></li>
<li><p>_PLATFORM_OS_WINDOWS_NT</p></li>
<li><p>_PLATFORM_OS_MAC</p></li>
<li><p>_PLATFORM_OS_SUN</p></li>
<li><p>_PLATFORM_OS_LINUX</p></li>
<li><p>_PLATFORM_OS_UNIX</p></li>
</ul>
</div>
<div id="subsection4" class="subsection"><h3><a name="subsection4">System fortran extension</a></h3>
<p>The SYSTEM fortran extension allows to execute an external program.
Depending on the compiler, the SYSTEM fortran extension is provided
as a subroutine or a function. The m_platform module <em>may</em> be informed
of the particular version of the SYSTEM extension at use and one
of the following pre-processing macro must be defined :</p>
<ul class="itemized">
<li><p>_PLATFORM_SYSTEM_SUBROUTINE</p></li>
<li><p>_PLATFORM_SYSTEM_FUNCTION</p></li>
</ul>
<p>See in your compiler manual for the specific settings.
 For example, this is a short list of compilers and the
 SYSTEM provided :</p>
<ul class="itemized">
<li><p>function : Intel Fortran, g95.</p></li>
<li><p>subroutine : gfortran,</p></li>
</ul>
</div>
<div id="subsection5" class="subsection"><h3><a name="subsection5">Environment variables extension</a></h3>
<p>The fortran 2003 standard introduces a standard way of accessing
 to the environment variables. Older compilers does not match
 that standard but provide extensions to access to environment variables.
 To inform the m_platform module of the particular environment
 variable extension, one of the following pre-processing macro <em>may</em>
 be defined :</p>
<ul class="itemized">
<li><p>_PLATFORM_INTEL_FORTRAN_PORTABILITY_ROUTINES</p></li>
<li><p>_PLATFORM_FORTRAN_2003</p></li>
</ul>
</div>
<div id="subsection6" class="subsection"><h3><a name="subsection6">Change directory fortran extension</a></h3>
<p>Depending on the compiler, the &quot;CHDIR&quot; fortran extension is provided
as a subroutine or a function.
To inform the m_platform module of the particular CHDIR extension,
one of the following pre-processing macro <em>may</em> be defined :</p>
<ul class="itemized">
<li><p>_PLATFORM_CHDIR_SUBROUTINE</p></li>
<li><p>_PLATFORM_CHDIR_FUNCTION</p></li>
</ul>
<p>See in your manual for the specific settings.
For example, this is a short list of compilers and their particular
CHDIR provided :</p>
<ul class="itemized">
<li><p>function : Intel Fortran, g95, gfortran</p></li>
<li><p>subroutine : gfortran</p></li>
</ul>
</div>
<div id="subsection7" class="subsection"><h3><a name="subsection7">File stat fortran extension</a></h3>
<p>Depending on the compiler, the &quot;STAT&quot; fortran extension is
provided as a subroutine or a function.
For example, this is a short list of compilers and their particular
STAT provided :</p>
<ul class="itemized">
<li><p>function : Intel Fortran, g95</p></li>
<li><p>subroutine : gfortran</p></li>
</ul>
<p>To inform the m_platform module of the particular STAT extension,
one of the following pre-processing macro <em>may</em> be defined :</p>
<ul class="itemized">
<li><p>_PLATFORM_STAT_SUBROUTINE</p></li>
<li><p>_PLATFORM_STAT_FUNCTION</p></li>
</ul>
</div>
<div id="subsection8" class="subsection"><h3><a name="subsection8">Example of compiler settings</a></h3>
<p>This is an abstract of all pre-processing macros for several compilers.</p>
<p>Compiler : <em>gfortran</em></p>
<ul class="itemized">
<li><p>_PLATFORM_FORTRAN_2003</p></li>
<li><p>_PLATFORM_CHDIR_SUBROUTINE</p></li>
<li><p>_PLATFORM_STAT_SUBROUTINE</p></li>
<li><p>_PLATFORM_SYSTEM_SUBROUTINE</p></li>
</ul>
<p>Compiler : <em>Intel Fortran</em></p>
<ul class="itemized">
<li><p>_PLATFORM_INTEL_FORTRAN_PORTABILITY_ROUTINES</p></li>
<li><p>_PLATFORM_CHDIR_FUNCTION</p></li>
<li><p>_PLATFORM_STAT_FUNCTION</p></li>
<li><p>_PLATFORM_SYSTEM_FUNCTION</p></li>
</ul>
<p>Compiler : <em>g95</em></p>
<ul class="itemized">
<li><p>_PLATFORM_FORTRAN_2003</p></li>
<li><p>_PLATFORM_CHDIR_FUNCTION</p></li>
<li><p>_PLATFORM_STAT_FUNCTION</p></li>
<li><p>_PLATFORM_SYSTEM_FUNCTION</p></li>
</ul>
</div>
</div>
<div id="section3" class="section"><h2><a name="section3">ROUTINES</a></h2>
<p>The module contains the following routines.</p>
<dl class="definitions">
<dt><a name="1"><b class="cmd">use m_platform</b></a></dt>
<dd><p>To import the subroutines, use this module.</p></dd>
<dt><a name="2"><b class="cmd">platform_system</b> (<i class="arg">command</i> <span class="opt">?, status?</span>)</a></dt>
<dd><dl class="arguments">
<dt><b class="type">character(len=*) ::</b> <i class="arg">command</i></dt>
<dd></dd>
<dt><b class="type">integer, intent ( out ), optional ::</b> <i class="arg">status</i></dt>
<dd></dd>
</dl>
<p>Run an external command or program, optionally retrieving the status of
that command. Under Windows the &quot;call system&quot; may generate the display of a console.
Optional argument <i class="arg">status</i> contains the execution status. 
Notice that the information contained
in it is not very reliable - some systems do not give any information.
The <i class="arg">command</i> to run is quite likely platform-dependent.</p></dd>
<dt><a name="3"><b class="cmd">platform_get_os()</b> result ( currentos )</a></dt>
<dd><dl class="arguments">
<dt><b class="type">integer ::</b> <i class="arg">currentos</i></dt>
<dd></dd>
</dl>
<p>Return the type of operating system, one of:
PLATFORM_OS_WINDOWS_95, PLATFORM_OS_WINDOWS_NT,
PLATFORM_OS_MACOS, PLATFORM_OS_SUNOS, PLATFORM_OS_LINUX,
PLATFORM_OS_UNIX.
The actual integer value should not be used directly ; instead, it
should be compared against the PLATFORM_OS_* public variables.</p></dd>
<dt><a name="4"><b class="cmd">platform_osstring</b> (<i class="arg">currentos</i>)</a></dt>
<dd><dl class="arguments">
<dt><b class="type">character(len=*), intent(out) ::</b> <i class="arg">currentos</i></dt>
<dd></dd>
</dl>
<p>Returns a string containing the current operating system running on the current machine,
one of &quot;Windows 95&quot;, &quot;Windows NT&quot;, &quot;MacOS&quot;, &quot;SunOS&quot;, 
&quot;Linux&quot; or &quot;Unix&quot;.</p></dd>
<dt><a name="5"><b class="cmd">platform_get_platform()</b> result ( currentplatform )</a></dt>
<dd><dl class="arguments">
<dt><b class="type">integer ::</b> <i class="arg">currentplatform</i></dt>
<dd></dd>
</dl>
<p>Return the category of platform, one of:
PLATFORM_PLATFORM_WINDOWS, PLATFORM_PLATFORM_MAC, PLATFORM_PLATFORM_UNIX
The actual integer value should not be used directly ; instead, it
should be compared against the PLATFORM_PLATFORM_* public variables.</p></dd>
<dt><a name="6"><b class="cmd">platform_platformstring</b> (<i class="arg">currentplatform</i>)</a></dt>
<dd><dl class="arguments">
<dt><b class="type">character(len=*), intent(out) ::</b> <i class="arg">currentplatform</i></dt>
<dd></dd>
</dl>
<p>Returns a string containing the current platform running on the current machine,
one of &quot;Windows&quot;, &quot;Mac&quot;, &quot;Unix&quot;.</p></dd>
<dt><a name="7"><b class="cmd">platform_get_environment_variable</b> ( <i class="arg">envvar</i> <i class="arg">, value</i>)</a></dt>
<dd><dl class="arguments">
<dt><b class="type">character(len=*) ::</b> <i class="arg">envvar</i></dt>
<dd></dd>
<dt><b class="type">character(len=*) ::</b> <i class="arg">value</i></dt>
<dd></dd>
</dl>
<p>Retrieve the value of the environment variable <i class="arg">envvar</i>. There is no indication of
whether the variable indeed exists and it is up to the calling program
to provide a string argument sufficiently long to hold the value.
The environment variable <i class="arg">envvar</i> is case-sensitive on
some platforms, case-insensitive on others. This is entirely up to the
platform.
As the underlying routines give no indication of the existence 
of the environment variable, it is probably best to
fill the <i class="arg">value</i> with a known value first (like: &quot;????&quot;) 
to check it.</p></dd>
<dt><a name="8"><b class="cmd">platform_cd</b> ( <i class="arg">dirname</i> <span class="opt">?, status?</span>)</a></dt>
<dd><dl class="arguments">
<dt><b class="type">character(len=*), intent(in) ::</b> <i class="arg">dirname</i></dt>
<dd></dd>
<dt><b class="type">integer, intent(out) , optional ::</b> <i class="arg">status</i></dt>
<dd></dd>
</dl>
<p>Change working directory to <i class="arg">dirname</i>. 
If <i class="arg">status</i> is supplied, it contains 0 on success or nonzero error code
upon return</p></dd>
<dt><a name="9"><b class="cmd">platform_stat</b> ( <i class="arg">filename</i> <i class="arg">, statarray</i> <span class="opt">?, status?</span>)</a></dt>
<dd><dl class="arguments">
<dt><b class="type">character(len=*), intent(in) ::</b> <i class="arg">filename</i></dt>
<dd></dd>
<dt><b class="type">integer, dimension (1:13) , intent(out)  ::</b> <i class="arg">filename</i></dt>
<dd></dd>
<dt><b class="type">integer, intent(out) , optional ::</b> <i class="arg">status</i></dt>
<dd></dd>
</dl>
<p>Get status of the file <i class="arg">filename</i> and fills the array <i class="arg">statarray</i>
with the following content.</p>
<ul class="itemized">
<li><p>statarray(1) Device ID</p></li>
<li><p>statarray(2) Inode number</p></li>
<li><p>statarray(3) File mode</p></li>
<li><p>statarray(4) Number of links</p></li>
<li><p>statarray(5) Owner's uid</p></li>
<li><p>statarray(6) Owner's gid</p></li>
<li><p>statarray(7) ID of device containing directory entry for file (0 if not available)</p></li>
<li><p>statarray(8) File size (bytes)</p></li>
<li><p>statarray(9) Last access time</p></li>
<li><p>statarray(10) Last modification time</p></li>
<li><p>statarray(11) Last file status change time</p></li>
<li><p>statarray(12) Preferred I/O block size (-1 if not available)</p></li>
<li><p>statarray(13) Number of blocks allocated (-1 if not available)</p></li>
</ul>
<p>If <i class="arg">status</i> is supplied, it contains 0 on success or nonzero error code
upon return</p></dd>
</dl>
</div>
<div id="copyright" class="section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2008 Arjen Markus &lt;arjenmarkus@sourceforge.net&gt;<br>
Copyright &copy; 2008 Michael Baudin &lt;michael.baudin@gmail.com&gt;</p>
</div>
</div></body></html>